﻿
var popDiv;
var popUp;
var ifmElement;
var ifm;
var inputText;
var cmbBtn;
var height;
var nowTimeTemp;

var WebCalendarWidth;
var WebCalendarNowSelect;
var WebCalendarDaysMonth;
var WebCalendarDay;
var WebCalendarDayObj;
var WebCalendarDateStyle;
var WebCalendarObjExport;
var WebCalendarInputDate;
var WebCalendarThisYear;
var WebCalendarThisMonth;
var WebCalendarThisDay;
var WebCalendarToday;
var WebCalendarDateReg;
var WebCalendarYearFall;
var WebCalendarFormat;
var WebCalendarTimeShow;
var WebCalendarDarkColor;
var WebCalendarLightColor;
var WebCalendarBtnBgColor;
var WebCalendarWordColor;
var WebCalendarWordDark;
var WebCalendarDayBgColor;
var WebCalendarTodayColor;
var WebCalendarDarkBorder;

function initIt(){
	initVar();
	inputText = element.document.createElement("<input type='text' name='"+name+"' cursor='default'/>");
	inputText.value=(value==null)?(""):(value);
	inputText.style.cssText = "height:"+height+"px;background='#FFFFFF';border-top: 1px solid " + WebCalendarDarkBorder + ";border-left: 1px solid " + WebCalendarDarkBorder + ";" + "border-right: 1px solid " + WebCalendarLightColor + "; border-bottom: 1px solid " + WebCalendarLightColor;
	element.appendChild(inputText);
	cmbBtn = element.document.createElement("INPUT");
	cmbBtn.type="button";
	cmbBtn.style.cssText = "hidefocus;height:"+height+"px;width:15px;color:#6666EE;background=url('"+imgdir+"cmb.jpg');margin-left:-4px;border-top: 1px solid " + WebCalendarDarkBorder + ";border-left: 0px solid " + WebCalendarDarkBorder + ";" + "border-right: 1px solid " + WebCalendarLightColor + "; border-bottom: 1px solid " + WebCalendarLightColor;
	element.appendChild(cmbBtn);
	inputText.attachEvent("onfocus",doblur);
	cmbBtn.attachEvent("onfocus",doblurBtn);
	cmbBtn.onclick=showCalendar;


	var tempElement=element.parentElement;
	if(WebCalendarTimeShow){
		inputText.size=19;
	}else{
		inputText.size=10;
	}

	while(tempElement.tagName!="BODY"){
		tempElement=tempElement.parentElement;
		if(tempElement==null){
			break;
		}
	}
	tempElement.attachEvent("onkeydown",doKeyDown);
}
function doblurBtn(){
	cmbBtn.blur();
}
function doKeyDown(){
	alert(window.event.keyCode)
	if(popUp){
		if(popUp.isOpen){
			switch(window.event.keyCode){
				case 27 : hiddenCalendar(); break;
				case 37 : prevM(); break;
				case 38 : prevY(); break;
				case 41 : nextM(); break;
				case 40 : nextY(); break;
				case 39 : nextM(); break;
				case 84 : setToday(); break;
			}
			window.event.keyCode = 0;
			window.event.returnValue= false;
		}
	}
}

function initVar(){

	WebCalendarDaysMonth  = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	WebCalendarDay        = new Array(42);            //定义日历展示用的数组
	WebCalendarDayObj     = new Array(42);            //定义日期展示控件数组
	WebCalendarDateStyle  = null;                     //保存格式化后日期数组
	WebCalendarObjExport  = null;                     //日历回传的显示控件
	WebCalendarInputDate  = null;                     //转化外的输入的日期(d/m/yyyy)
	WebCalendarThisYear   = new Date().getFullYear(); //定义年的变量的初始值
	WebCalendarThisMonth  = new Date().getMonth()+ 1; //定义月的变量的初始值
	WebCalendarThisDay    = new Date().getDate();     //定义日的变量的初始值
	WebCalendarToday      = WebCalendarThisDay +"/"+ WebCalendarThisMonth +"/"+WebCalendarThisYear;   //今天(d/m/yyyy)
	WebCalendarNowSelect  = WebCalendarToday;
	WebCalendarDateReg    = "";           //日历格式验证的正则式
	WebCalendarYearFall   = 50;           //定义年下拉框的年差值
	WebCalendarFormat     = "yyyy-mm-dd"; //回传日期的格式
	WebCalendarYMformat   = "yyyy-mm";	//回传的年月格式
	WebCalendarTimeShow   = false;//(showTime!=null&&showTime!='false');        //是否返回时间
	if(WebCalendarTimeShow){
		WebCalendarWidth = 160;
		WebCalendarHeight = 210;
	}else{
		WebCalendarWidth = 160;
		WebCalendarHeight = 193;
	}
	WebCalendarDarkColor  =  "#BEE1FD"   //控件的暗色
	WebCalendarLightColor = "#FFFFFF"   //控件的亮色
	WebCalendarBtnBgColor ="#eaf6fb"    //控件的按钮背景色
	WebCalendarWordColor  = "#000000"   //控件的文字颜色
	WebCalendarWordDark   = "#BBBBBB"    //控件的暗文字颜色
	WebCalendarDayBgColor = "#eaf6fb"    //日期数字背景色
	WebCalendarTodayColor = "#197799"   //今天在日历上的标示背景色
	WebCalendarDarkBorder = "#eaf6fb"    //日期显示的立体表达色

	WebCalendarborderColorLight="#ffffff";//边框亮色
	WebCalendarborderColorDark="#eaf6fb";//边框暗色
	height="20"

	nowTimeTemp = new Date();
}

function doblur(){
	cmbBtn.focus();
}

function setday(B_obj,T_obj){
	if(popUp==null) {
		if (!window.createPopup) {
			var __createPopup = function() {
				var SetElementStyles = function( element, styleDict ) {
					var style = element.style ;
					for ( var styleName in styleDict )style[ styleName ] = styleDict[ styleName ] ; 
				}
				var eDiv = document.createElement( 'div' ); 
				SetElementStyles( eDiv, { 'position': 'absolute', 'top': 0 + 'px', 'left': 0 + 'px', 'width': 0 + 'px', 'height': 0 + 'px', 'zIndex': 1000, 'display' : 'none', 'overflow' : 'hidden' } ) ;
				eDiv.body = eDiv ;
				var opened = false ;
				var setOpened = function( b ) {
					opened = b; 
				}
				var getOpened = function() {
					return opened ; 
				}
				var getCoordinates = function( oElement ) {
					var coordinates = {x:0,y:0} ; 
					while( oElement ) {
						coordinates.x += oElement.offsetLeft ;
						coordinates.y += oElement.offsetTop ;
						oElement = oElement.offsetParent ;
					}
					return coordinates ;
				}
				return {htmlTxt : '', document : eDiv, isOpen : getOpened(), isShow : false, hide : function() { SetElementStyles( eDiv, { 'top': 0 + 'px', 'left': 0 + 'px', 'width': 0 + 'px', 'height': 0 + 'px', 'display' : 'none' } ) ; eDiv.innerHTML = '' ; this.isShow = false ; }, show : function( iX, iY, iWidth, iHeight, oElement ) { if (!getOpened()) { document.body.appendChild( eDiv ) ; setOpened( true ) ; } ; this.htmlTxt = eDiv.innerHTML ; if (this.isShow) { this.hide() ; } ; eDiv.innerHTML = this.htmlTxt ; var coordinates = getCoordinates ( oElement ) ; eDiv.style.top = ( iX + coordinates.x ) + 'px' ; eDiv.style.left = ( iY + coordinates.y ) + 'px' ; eDiv.style.width = iWidth + 'px' ; eDiv.style.height = iHeight + 'px' ; eDiv.style.display = 'block' ; this.isShow = true ; } }
			}
			window.createPopup = function() {
				return __createPopup(); 
			}
		}
		popUp = window.createPopup();
		var oPopBody = popUp.document.body;
		writeIframe();
	}
	popUp.show( event.screenX+10 , event.screenY+10 , WebCalendarWidth+2, WebCalendarHeight+2);
	calendar(B_obj,T_obj);
}


function writeIframe(){
		var selYLeft = 58;
		var selMleft=133;
		/*if(WebCalendarTimeShow){
			selYLeft=58;
			selMleft=133;
		}*/
      		var strIframe = "<html><head><style>" + "*{font-size: 12px;}" + ".bg{  color: " + WebCalendarLightColor + "; cursor: default; background-color: " + WebCalendarDarkColor + ";}" +
                "table#tableMain{ width: "+WebCalendarWidth+"; height: 180;}" +
                " table#tableWeek td{ text-align:center; color: " + WebCalendarLightColor + ";}" +
                "table#tableDay  td{ font-weight: bold;}" +
                "td#kxYearHead, td#kxYearMonth{ text-align:center; color: " + WebCalendarWordColor + "}" +
                ".over { text-align: center; border-top: 1px solid " + WebCalendarLightColor + ";border-left: 1px solid " + WebCalendarLightColor + ";" + "border-right: 1px solid " + WebCalendarDarkBorder + "; border-bottom: 1px solid " + WebCalendarDarkBorder + ";}" +
		".selected { text-align: center; border-top: 1px solid " + WebCalendarDarkBorder + ";border-left: 1px solid " + WebCalendarDarkBorder + ";" + "border-right: 1px solid " + WebCalendarLightColor + "; border-bottom: 1px solid " + WebCalendarLightColor + ";}" +
                ".out{ text-align: center; border-top: 1px solid " + WebCalendarLightColor + "; border-left: 1px solid " + WebCalendarLightColor + ";" + "border-bottom: 1px solid " + WebCalendarDarkBorder + "; border-right: 1px solid " + WebCalendarDarkBorder + "}" +
                "input{ border: 1px solid " + WebCalendarDarkColor
                + "; padding-top: 1px; height: 20; cursor: hand;" + " color:" + WebCalendarWordColor + "; background-color: " + WebCalendarBtnBgColor + "}" +
                "</style></head>";

   		strIframe+="<body onselectstart='return false' scrolling='no' style='overflow:hidden;margin: 0px;border: 1px solid "+WebCalendarDarkBorder+";' oncontextmenu='return false'><form name=kx>";

		strIframe += "<select name=tmpYearSelect  style='z-index:1;position:absolute;top:3;left:"+selYLeft+";display:none'>"+
		"</select>"+
		"<select name=tmpMonthSelect style='z-index:1; position:absolute;top:3;left:"+selMleft+";display:none'"+
		"></select>"+

		"<table id=tableMain class=bg border=0 cellspacing=0 cellpadding=1>"+
		"<tr><td height=20 bgcolor='"+ WebCalendarLightColor +"'>"+
		"    <table width=100% id=tableHead border=0 cellspacing=1 cellpadding=0><tr align=center>"+
		"    <td align='center' height=20 class=bg ><input type='button' style='width:0px;height:0px;'><input name=prevYear title='向前翻 1 年' style='cursor:hand;font-family:webdings;padding:0 0 0 0;' type=button value='7'"+
    		"    onfocus='this.blur()'><input"+
    		"    onfocus='this.blur()' name=prevMonth title='向前翻 1 月' style='cursor:hand;font-family:webdings;padding:0 0 0 0;'  type=button value='3'></td>"+
		"    <td width='120' id=kxYearHead title='点击此处选择年份'"+
		"        onmouseover=\"this.bgColor='"+WebCalendarDarkColor+"'; this.style.color='"+WebCalendarLightColor+"';\""+
		"        onmouseout=\"this.bgColor='"+WebCalendarLightColor+"'; this.style.color='"+WebCalendarWordColor+"';\"></td>"+
		"    <td width='120' id=kxYearMonth title='点击此处选择月份'"+
		"        onmouseover=\"this.bgColor='"+WebCalendarDarkColor+"'; this.style.color='"+WebCalendarLightColor+"'\""+
		"        onmouseout=\"this.bgColor='"+WebCalendarLightColor+"'; this.style.color='"+WebCalendarWordColor+"'\"></td>"+
		"    <td align='center' class=bg ><input title='向后翻 1 月' name=nextMonth onclick='parent.nextM()' style='cursor:hand;font-family:webdings;padding:0 0 0 0;'  type=button value='4'"+
    		"    onfocus='this.blur()'><input name=nextYear title='向后翻 1 年' onclick='parent.nextY()' style='cursor:hand;font-family:webdings;padding:0 0 0 0;'  type=button value='8'"+
    		"    onfocus='this.blur()' style='kx:expression(this.disabled=parent.WebCalendarThisYear==9999)'></td></tr></table>"+
		"</td></tr><tr><td height=20px>";
		strIframe += "<table id=tableWeek border=1 width=100% cellpadding=0 cellspacing=0";
		strIframe += " borderColorLight='"+WebCalendarborderColorLight+"' borderColorDark='"+WebCalendarborderColorDark+"'>"+
		"    <tr align='center' height=20px><td width='20'>日</td><td width='20'>一</td><td width='20'>二</td><td width='20'>三</td><td width='20'>四</td><td width='20'>五</td><td width='20'>六</td></tr></table>"+
		"</td></tr><tr><td valign='middle' height='122px'>"+
		"    <table bgcolor='"+WebCalendarDarkColor+"' id='tableDay' height='100%' width='100%' cellspacing=0 cellpadding=0>";

        for (var x = 0; x < 5; x++)
        {
                strIframe += "<tr height='20px'>";
                for (var y = 0; y < 7; y++)
                        strIframe += "<td class=out id='kxDay" + (x * 7+y) + "' width='20'></td>";
                strIframe += "</tr>";
        }
		strIframe += "<tr>";

         for(var x=35; x<42; x++) {
			 strIframe += "<td class=out id='kxDay"+ x +"'></td>";
		 }

         strIframe +="</tr></table>"+
    "    </td></tr><tr><td height=20 bgcolor='"+WebCalendarDarkColor+"' valign='top'>"+
    "    <table border=0 cellpadding=0 cellspacing=0 width=100%>"+
    "    <tr><td align='center' height=0>";
    if(WebCalendarTimeShow){
    	//var nowTimeTemp = new Date();
    	var tempHouSelectStr = "<select id='hou' multiple size='1'>";
    	var tempMinSelectStr = "</select>时<select id='min' multiple size='1'>";;
    	var tempSecSelectStr = "</select>分<select id='sec'  size='1' multiple>";
    	var hN = nowTimeTemp.getHours();
    	var mN = nowTimeTemp.getMinutes();
    	var sN = nowTimeTemp.getSeconds();
    	for(var iii=0;iii<60;iii++){
    		if(iii<24){
	    		tempHouSelectStr+="<option value='"+iii+"'";
	    		if(iii==hN){
	    			tempHouSelectStr +=" selected";
	    		}
	    		tempHouSelectStr+=">"+appendZero(iii)+"</option>";
	    	}
	    	tempMinSelectStr+="<option value='"+iii+"'";
    		if(iii==mN){
    			tempMinSelectStr +=" selected";
    		}
    		tempMinSelectStr+=">"+appendZero(iii)+"</option>";

    		tempSecSelectStr+="<option value='"+iii+"'";
    		if(iii==sN){
    			tempSecSelectStr +=" selected";
    		}
    		tempSecSelectStr+=">"+appendZero(iii)+"</option>";

    	}
    	strIframe+=tempHouSelectStr;
    	strIframe+=tempMinSelectStr;
    	strIframe+=tempSecSelectStr;
    	strIframe+="</select>秒";

	}
    strIframe+="</td></tr>"+
    "    <tr>"+
    "<td align='center'><input name=today type=button value='今天' onfocus='this.blur()' style='width: 30' title='当前日期'>&nbsp;&nbsp;&nbsp;<input type='button' name='closeCalendar' value='关闭' style='width: 30' title='关闭'></td></tr></table>"+
    "</td></tr><table></form></body></html>";

    with(popUp)
    {
	document.writeln(strIframe);
	document.close();
	with(document.all){
		kxYearHead.onclick=returnY;
		kxYearMonth.onclick=returnYM;
		prevYear.onclick=prevY;
		prevMonth.onclick=prevM;
		nextMonth.onclick=nextM;
		nextYear.onclick=nextY;
		today.onclick=setToday;
		tmpYearSelect.onchange=newYearSelect;
		tmpYearSelect.onblur=hiddenSelect;
		tmpMonthSelect.onchange=newMonthSelect;
		tmpMonthSelect.onblur=hiddenSelect;
		//doOk.onclick=returnDate;
		closeCalendar.onclick=hiddenCalendar;

		for(var i=0; i<42; i++){
	            WebCalendarDayObj[i] = eval("kxDay"+ i);
	            WebCalendarDayObj[i].onmouseover = dayMouseOver;
	            WebCalendarDayObj[i].onmouseout  = dayMouseOut;
	            WebCalendarDayObj[i].onclick     = newDateSelect;
	        }
	   	}
    }
}
function newYearSelect(){
	WebCalendarThisYear =this.value;
	writeCalendar();
	hiddenSelect(popUp.document.all.tmpYearSelect);
}

function hidenYearSelect(){
	hiddenSelect(popUp.document.all.tmpYearSelect);
}

function newMonthSelect(){
	WebCalendarThisMonth=this.value;
	hiddenSelect(popUp.document.all.tmpMonthSelect);
	writeCalendar();
}


function hidenMonthSelect(){
	hiddenSelect(popUp.document.all.tmpMonthSelect);
}

function hiddenAllSelect(){
	hidenMonthSelect();
	hidenYearSelect();
}
//返回今天的日期（可以有时间）
function setToday(){
	WebCalendarNowSelect = WebCalendarToday;
	var a = WebCalendarToday.split("/");
	WebCalendarThisYear = a[2];
	WebCalendarThisMonth  = a[1];
	WebCalendarThisDay = a[0];
	if(WebCalendarTimeShow){
		nowTimeTemp = new Date();
		writeIframe();
	}
	returnDate();
}



function calendar(B_obj,T_obj){
    var e = window.event.srcElement;
    if (T_obj==null)
    	WebCalendarObjExport = e;
    else
    	WebCalendarObjExport	=T_obj;
    WebCalendarObjExport.blur();
    if  (!WebCalendarTimeShow) WebCalendarDateReg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
    else WebCalendarDateReg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
    try{
        if (WebCalendarObjExport.value.trim() != ""){
            WebCalendarDateStyle = WebCalendarObjExport.value.trim().match(WebCalendarDateReg);
            if (WebCalendarDateStyle == null)
            {
                WebCalendarThisYear   = new Date().getFullYear();
                WebCalendarThisMonth  = new Date().getMonth()+ 1;
                WebCalendarThisDay    = new Date().getDate();
                //alert("原文本框里的日期有错误！\n可能与你定义的显示时分秒有冲突！");
                writeCalendar(); return false;
            }
            else
            {
                WebCalendarThisYear   = parseInt(WebCalendarDateStyle[1], 10);
                WebCalendarThisMonth  = parseInt(WebCalendarDateStyle[3], 10);
                WebCalendarThisDay    = parseInt(WebCalendarDateStyle[4], 10);
                WebCalendarInputDate  = parseInt(WebCalendarThisDay, 10) +"/"+ parseInt(WebCalendarThisMonth, 10) +"/"+
                parseInt(WebCalendarThisYear, 10);
                WebCalendarNowSelect = WebCalendarInputDate;
                writeCalendar();
                return;
            }
        }  else writeCalendar();
    }  catch(e){writeCalendar();}
}

function prevM()  //往前翻月份
{
    WebCalendarThisDay = 1;
    if (WebCalendarThisMonth==1)
    {
        WebCalendarThisYear--;
        WebCalendarThisMonth=13;
    }
    WebCalendarThisMonth--;
    writeCalendar();
}
function nextM()  //往后翻月份
{
    WebCalendarThisDay = 1;
    if (WebCalendarThisMonth==12)
    {
        WebCalendarThisYear++;
        WebCalendarThisMonth=0;
    }
    WebCalendarThisMonth++; writeCalendar();
}
function prevY(){WebCalendarThisDay = 1; WebCalendarThisYear--; writeCalendar();}//往前翻 Year

function nextY(){WebCalendarThisDay = 1; WebCalendarThisYear++; writeCalendar();}//往后翻 Year

function hiddenSelect(nows){
	try{
		var ee=nows;
		for(var i=(ee.options.length-1); i>-1; i--)
		{

			ee.options.remove(i);
		}
		nows.style.display="none";
	}catch(e){}
}

function hiddenCalendar(){
	if(popUp){
		if(popUp.isOpen){
			popUp.hide();
		}
	}
	try{
            WebCalendarObjExport.onchange();
	}catch(e){
        }
};
//日期自动补零程序
function appendZero(n){
	return(("00"+ n).substr(("00"+ n).length-2));
}

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g,"");
}

function dayMouseOver() {
        this.style.backgroundColor = WebCalendarWordDark;
        var d = WebCalendarDay[this.id.substr(5)];
        if (WebCalendarNowSelect == d) {
                return ;
        }
        this.className = "over";
        if (d.split("/")[1] == WebCalendarThisMonth) {
                this.style.color = WebCalendarLightColor;
        }else{
        	this.style.color = WebCalendarLightColor;
        }
}

function dayMouseOut() {
        var d = WebCalendarDay[this.id.substr(5)];
        if (WebCalendarNowSelect == d) {
        	if(WebCalendarNowSelect == WebCalendarToday){
        		this.style.background = WebCalendarTodayColor;
        	}
                return ;
        }
        if (WebCalendarInputDate==d){
		        this.bgColor = WebCalendarWordDark;
		        this.style.color = WebCalendarLightColor;
	}
        this.className = "out";
        a = d.split("/");
        this.style.removeAttribute('backgroundColor');
        if (a[1] == WebCalendarThisMonth && d != WebCalendarToday) {
                if (WebCalendarDateStyle && a[0] == parseInt(WebCalendarDateStyle[4], 10)) {
                        this.style.background = WebCalendarLightColor;
                }
                this.style.color = WebCalendarWordColor;
        }else if(d == WebCalendarToday){
        	this.style.color = WebCalendarLightColor;
        }else{
        	this.style.color = WebCalendarWordDark;
	}
}
function writeCalendar() //对日历显示的数据的处理程序
{
    var y = WebCalendarThisYear;
    var m = WebCalendarThisMonth;
    var d = WebCalendarThisDay;
    WebCalendarDaysMonth[1] = (0==y%4 && (y%100!=0 || y%400==0)) ? 29 : 28;
    if (!(y<=9999 && y >= 1000 && parseInt(m, 10)>0 && parseInt(m, 10)<13 && parseInt(d, 10)>0)){
        alert("对不起，你输入了错误的日期！");
        WebCalendarThisYear   = new Date().getFullYear();
        WebCalendarThisMonth  = new Date().getMonth()+ 1;
        WebCalendarThisDay    = new Date().getDate();
    }
    y = WebCalendarThisYear;
    m = WebCalendarThisMonth;
    d = WebCalendarThisDay;
    popUp.document.all.kxYearHead.innerText  = y +" 年";
    popUp.document.all.kxYearMonth.innerText = parseInt(m, 10) +" 月";
    WebCalendarDaysMonth[1] = (0==y%4 && (y%100!=0 || y%400==0)) ? 29 : 28; //闰年二月为29天
    var w = new Date(y, m-1, 1).getDay();
    var prevDays = m==1  ? WebCalendarDaysMonth[11] : WebCalendarDaysMonth[m-2];
    for(var i=(w-1); i>=0; i--) //这三个 for 循环为日历赋数据源（数组 WebCalendarDay）格式是 d/m/yyyy
    {
        WebCalendarDay[i] = prevDays +"/"+ (parseInt(m, 10)-1) +"/"+ y;
        if(m==1) WebCalendarDay[i] = prevDays +"/"+ 12 +"/"+ (parseInt(y, 10)-1);
        prevDays--;
    }
    for(var i=1; i<=WebCalendarDaysMonth[m-1]; i++) WebCalendarDay[i+w-1] = i +"/"+ m +"/"+ y;
    for(var i=1; i<42-w-WebCalendarDaysMonth[m-1]+1; i++)
    {
        WebCalendarDay[WebCalendarDaysMonth[m-1]+w-1+i] = i +"/"+ (parseInt(m, 10)+1) +"/"+ y;
        if(m==12) WebCalendarDay[WebCalendarDaysMonth[m-1]+w-1+i] = i +"/"+ 1 +"/"+ (parseInt(y, 10)+1);
    }
    //显示当前选择的时间：
    var tempArray=WebCalendarNowSelect.split("/");
    //popUp.document.all.nowSelectObj.innerHTML=tempArray[2]+"年"+appendZero(tempArray[1])+"月"+appendZero(tempArray[0])+"日";
    //这个循环是根据源数组写到日历里显示
    for(var i=0; i<42; i++){
	    	var a = WebCalendarDay[i].split("/");
	    	WebCalendarDayObj[i].className='out';
	        WebCalendarDayObj[i].innerText    = a[0];
	        WebCalendarDayObj[i].title        = a[2] +"-"+ appendZero(a[1]) +"-"+ appendZero(a[0]);
	        WebCalendarDayObj[i].bgColor      = WebCalendarDayBgColor;
	        WebCalendarDayObj[i].style.color  = WebCalendarWordColor;
	        WebCalendarDayObj[i].style.removeAttribute('backgroundColor');

	        if ((i<10 && parseInt(WebCalendarDay[i], 10)>22) || (i>27 && parseInt(WebCalendarDay[i], 10)<14)){
	        	WebCalendarDayObj[i].style.color = WebCalendarWordDark;
	        }
	        //设置输入框里的日期在日历上的颜色
	        if (WebCalendarInputDate==WebCalendarDay[i]){
		        WebCalendarDayObj[i].bgColor = WebCalendarDarkColor;
		        WebCalendarDayObj[i].style.color = WebCalendarLightColor;
	        }

	        if (WebCalendarDay[i] == WebCalendarToday)      //设置今天在日历上反应出来的颜色
	        {

	        	WebCalendarDayObj[i].bgColor = WebCalendarTodayColor; WebCalendarDayObj[i].style.color = WebCalendarLightColor;
	        }
	    	if(WebCalendarDay[i] == WebCalendarNowSelect){
	    		WebCalendarDayObj[i].className='selected';
	    		WebCalendarDayObj[i].style.color=WebCalendarLightColor;
	    		if(WebCalendarToday!=WebCalendarNowSelect){
	    			WebCalendarDayObj[i].style.background = WebCalendarDarkColor;
	    		}
	    	}

 	}
 	if(WebCalendarTimeShow){
			popUp.document.all.hou.value = nowTimeTemp.getHours();
			popUp.document.all.min.value = nowTimeTemp.getMinutes();
			popUp.document.all.sec.value = nowTimeTemp.getSeconds();
			//window.status+=[popUp.document.all.sec.value+"-"+dateNow.getSeconds()+"-"+popUp.document.all.hou.selectedIndex];
	}
}
//根据日期格式等返回用户选定的日期
function newDateSelect()
{
    if(WebCalendarObjExport)
    {
        var returnValue;
        var selectObj = (arguments.length==0) ? WebCalendarDay[this.id.substr(5)]: arguments[0];
        var a = selectObj.split("/");
        WebCalendarNowSelect = WebCalendarDay[this.id.substr(5)];
        if(a[2]>WebCalendarThisYear){
        	nextM();
        }else if(a[2]<WebCalendarThisYear){
        	prevM();
        }else if(a[1]>WebCalendarThisMonth){
        	nextM();
        }else if(a[1]<WebCalendarThisMonth){
        	prevM();
        }
        else{
	        writeCalendar();
				}
				returnDate();
    }
}
//返回日期
function returnDate() {
        if (WebCalendarObjExport) {
                var returnValue;
                var a = (arguments.length == 0) ? WebCalendarNowSelect.split("/"): arguments[0].split("/");
                var d = WebCalendarFormat.match(/^(\w{4})(-|\/)(\w{1,2})\2(\w{1,2})$/);
                if (d == null) {
                        alert("你设定的日期输出格式不对！\r\n\r\n请重新定义 WebCalendarFormat ！");
                        return false;
                }
                var flag = d[3].length == 2 || d[4].length == 2; //判断返回的日期格式是否要补零
                returnValue = flag ? a[2] + d[2] + appendZero(a[1]) + d[2] + appendZero(a[0]): a[2] + d[2] + a[1] + d[2] + a[0];
                if (WebCalendarTimeShow) {
                        var h = popUp.document.all.hou.value;
                        var m = popUp.document.all.min.value;
                        var s = popUp.document.all.sec.value;
                        nowTimeTemp.setHours(h);
												nowTimeTemp.setMinutes(m);
												nowTimeTemp.setSeconds(s);
                        returnValue += flag ? " " + appendZero(h) + ":" + appendZero(m) + ":" + appendZero(s): " " + h + ":" + m + ":" + s;
                }
                var tempValue = WebCalendarObjExport.value;
                WebCalendarObjExport.value = returnValue;
                hiddenCalendar();
                if(tempValue != returnValue){
                	//onchangeID.fire();
                }
        }
}
//返回年月
function returnYM(){
	if(WebCalendarObjExport)    {
		var returnValue;
		y = WebCalendarThisYear;
	  m = WebCalendarThisMonth;
		var tt=WebCalendarYMformat.match(/^(\w{4})(-|\/|.|)(\w{1,2})$/);
		if(tt==null){alert("你设定的日期输出格式不对！\r\n\r\n请重新定义 WebCalendar.YMformat ！"); return false;}
		var flag =tt[3].length==2;
		returnValue = flag ? y +tt[2]+ appendZero(m):y +m;
		WebCalendarObjExport.value = returnValue;
		hiddenCalendar();
	}
}
//返回年
function returnY(){
	if(WebCalendarObjExport)    {
		y = WebCalendarThisYear;
		WebCalendarObjExport.value = y;
		hiddenCalendar();
	}
}
initVar();
